/*
 Erica Sadun, http://ericasadun.com
 iPhone Developer's Cookbook, 3.0 Edition
 BSD License, Use at your own risk
 */

#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
#import "ABContact.h"
#import "ABGroup.h"

@interface ABContactsHelper : NSObject

/* Khoai: support block accessor */

// Address Book
+ (ABAddressBookRef) addressBook;

// Address Book Contacts and Groups
+ (void)getContactsUsingBlock:(void(^)(NSArray *contacts))block;
+ (NSArray *)groups; // groups

// Counting
+ (int)contactsCount;
+ (int)contactsWithImageCount;
+ (int)contactsWithoutImageCount;
+ (int)numberOfGroups;

// Sorting
+ (BOOL)firstNameSorting;

// Add contacts and groups
+ (BOOL)addContact:(ABContact *)aContact withError:(NSError **)error;
+ (BOOL)addGroup:(ABGroup *)aGroup withError:(NSError **)error;

// Find contacts
+ (void)getContactsMatchingName:(NSString *)fname usingBlock:(void(^)(NSArray *result))block;
+ (void)getContactsMatchingName:(NSString *)fname andName:(NSString *)lname usingBlock:(void(^)(NSArray *result))block;
+ (void)getContactsMatchingPhone:(NSString *)number usingBlock:(void(^)(NSArray *result))block;

// Find groups
+ (void)getGroupsMatchingName:(NSString *)fname usingBlock:(void(^)(NSArray *result))block;
@end

// For the simple utility of it. Feel free to comment out if desired
@interface NSString (cstring)
@property (readonly) char *UTF8String;
@end